/**
 * Created by luohao on 2016/10/11.
 */
$("table").on("click", ".delete", function () {
    // alert($(this).attr("value"));
    $.ajax({
        url:"bookmanager/book",
        type:"delete",
        data:{"userid":$(this).attr("value")},
        dataType:"json",
        success:function(data){
            switch(data.status) {
                case 1:
                    alert(data.mag);
                    window.location.reload();
                    break;
                case 0:
                    alert(data.mag);
                    break;
            }
        }
    });
});
//点击添加图书
$(".addbook").on("click",function () {
    $("#quit").show();
});
//取消添加图书
$("#quit #returnto").on("click",function(){
    $("#quit").hide();
});

//弹出修改窗
$("body").on("click",".tchange",function(){
    //获取书籍信息
    var otr = $(this).parents("tr").find("td");
    var bookId = otr.eq(0).html();
    var bookName = otr.eq(1).html();
    bookName=bookName.substring(1,bookName.length-1);
    var author = otr.eq(2).html();
    var outt = otr.eq(3).html();
    //
    $("#bkid").val(bookId);
    $("#bkname").val(bookName);
    $("#aut").val(author);
    $("#pre").val(outt);


   $("#change").show();
});
//修改窗消失
$("#returntos").click(function (){
    $("#change").hide();
});

//添加图书
$("div #addbook").on("click", "#toaddbook", function () {
    $.ajax({
        url:"bookmanager",
        type:"post",
        data:{"bookname":$("#bookname").val(),"author":$("#author").val(),"press":$("#press").val()},
        dataType:"json",
        success:function(data){
            switch(data.status) {
                case 1:
                    alert(data.mag);
                    window.location.reload();
                    break;
                case 0:
                    alert(data.mag);
                    break;
            }
        }
    });
});

//修改图书
$("div #changebook").on("click", "#tochangebook", function () {
    $.ajax({
        url:"bookmanager/book/edit",
        type:"get",
        data:{"bookid":$("#bkid").val(),"bookname":$("#bkname").val(),"author":$("#aut").val(),"press":$("#pre").val()},
        dataType:"json",
        success:function(data){
            switch(data.status) {
                case 1:
                    alert(data.mag);
                    window.location.reload();
                    break;
                case 0:
                    alert(data.mag);
                    break;
            }
        }
    });
});